package com.systop.scos.news.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Store;

import com.systop.common.modules.security.user.model.User;
import com.systop.core.model.BaseModel;

/**
 * 新闻表
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "news")
public class News extends BaseModel {
	
	/** 主键 */
	private Integer id;

	/** 标题 */
	private String title;

	/** 内容 */
	private String content;

	/** 创建时间 */
	private Date createTime;

	/** 修改时间 */
	private Date updateTime;

	/** 录入者 */
	private User author;

	/** 点击数 */
	private Integer hits;
	
	/** 附件 */
	private String attachIds;
	
	/** 新闻类别 */
	private NewsType newsType;
	
	/**
	 * 新闻评论
	 */
	private Set<NewsComment> newsComments = new HashSet<NewsComment>(0);
	
	/** 构造方法 */
	public News() {
	}

	/** 构造方法 */
	public News(Integer id) {
		this.id = id;
	}

	@Id
	@GeneratedValue(generator = "hibseq")
	@GenericGenerator(name = "hibseq", strategy = "hilo")
	@Column(name = "id", nullable = false)
	@DocumentId
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "Title", length = 255)
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

  @Column(name = "Content")
  @Type(type = "text")
  @Field(name = "content", index = Index.TOKENIZED, store = Store.YES)
	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "Create_Time")
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "Update_Time")
	public Date getUpdateTime() {
		return this.updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "Author")
	public User getAuthor() {
		return this.author;
	}

	public void setAuthor(User author) {
		this.author = author;
	}

	@Column(name = "Hits", precision = 22, scale = 0)
	public Integer getHits() {
		return this.hits;
	}

	public void setHits(Integer hits) {
		this.hits = hits;
	}
	
	@Column(name = "AttachIds")
  public String getAttachIds() {
		return attachIds;
	}

	public void setAttachIds(String attachIds) {
		this.attachIds = attachIds;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "NewsType_Id")
	public NewsType getNewsType() {
		return newsType;
	}

	public void setNewsType(NewsType newsType) {
		this.newsType = newsType;
	}
	
	@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "news")
	public Set<NewsComment> getNewsComments() {
		return newsComments;
	}

	public void setNewsComments(Set<NewsComment> newsComments) {
		this.newsComments = newsComments;
	}

}
